<template>
	<div class="thisPage flex-row-c-c">
		<div class="echartItem" ref="echartItem"></div>
		<div class="echartItem" ref="echartItem1"></div>
	</div>
</template>

<script>
	import * as echarts from 'echarts';
	export default {
		data() {
			return {
				option: null,
				myChart: null
			}
		},
		methods: {

		},
		created() {
			this.option = {
				legend: {
				
				},
				tooltip: {

				},
				dataset: {
					// 提供一份数据。
					source: [
						['product', '2015', '2016', '2017'],
						['Matcha Latte', 43.3, 85.8, 93.7],
						['Milk Tea', 83.1, 73.4, 55.1],
						['Cheese Cocoa', 86.4, 65.2, 82.5],
						['Walnut Brownie', 72.4, 53.9, 39.1]
					]
				},
				// 声明一个 X 轴，类目轴（category）。默认情况下，类目轴对应到 dataset 第一列。
				xAxis: {
					type: 'category'
				},
				// 声明一个 Y 轴，数值轴。
				yAxis: {
					type: 'value'
				},
				// 声明多个 bar 系列，默认情况下，每个系列会自动对应到 dataset 的每一列。
				series: [{
					type: 'bar',
					stack: 'ad'
				}, {
					type: 'bar',
					stack: 'ad'
				}, {
					type: 'bar'
				}]
			};
		},
		mounted() {
			// console.log(this.$refs.echartItem)
			this.myChart = echarts.init(this.$refs.echartItem, 'dark')
			this.myChart.setOption(this.option)
			
			this.myChart.on('click', (params) => {
				console.log('params',params);
			})

			echarts.init(this.$refs.echartItem1, 'dark').setOption({
				xAxis: {
					type: 'category',
					data: ['Matcha Latte', 'Milk Tea', 'Cheese Cocoa', 'Walnut Brownie']
				},
				legrnd: {
					left: 'center'
				},
				tooltip:{
					trigger: 'axis',
				},
				yAxis: {},
				series: [{
						type: 'bar',
						name: '2015',
						stack: 'ad',
						background: true,
						data: [89.3, 92.1, 94.4, 85.4]
					},
					{
						type: 'bar',
						name: '2016',
						stack: 'ad',
						data: [95.8, 89.4, 91.2, 76.9]
					},
					{
						type: 'bar',
						name: '2017',
						data: [97.7, 83.1, 92.5, 78.1]
					}
				]
			})

		},
		beforeDestroy() {
			// console.log('销毁前');
			this.myChart.dispose()
			// console.log('已销毁');
		}
	}
</script>

<style lang="scss" scoped>
	.thisPage {
		width: 100%;
		min-height: 100vh;
		background-color: aqua;

		.echartItem {
			width: 300px;
			height: 300px;
			border: 1px solid black;
		}
	}
</style>